package lapsnake.model.misc;

import lapsnake.model.*;
import lapsnake.model.data.*;
import lapsnake.py.ast.ASTHelperFactory; 
import lapsnake.ui.JTreeLabel;

import java.awt.Component;
import java.beans.PropertyVetoException;

import org.python.antlr.ast.*;

/**Wrapper class with helper functions for comprehension nodes*/
public class LapComprehension extends LapNode {
	public final SingleChild<LapExpression> target = new SingleChild<>(this, LapExpression.class);
	public final SingleChild<LapExpression> iter = new SingleChild<>(this, LapExpression.class);
	public final ChildList<LapExpression> ifs = new ChildList<>(this, LapExpression.class, true);
	
	public LapComprehension(PyAST pyAST, ChildField<? super LapComprehension> parent, comprehension node) throws PropertyVetoException {
		super(pyAST, parent, node);
		
		ASTHelperFactory.makeHelper(pyAST, target, node.getInternalTarget());
		ASTHelperFactory.makeHelper(pyAST, iter, node.getInternalIter());
		ASTHelperFactory.makeHelpers(pyAST, ifs, node.getInternalIfs());
		
		buildTextNodes(node);
	}

	@Override
	protected Component getFillerComponent(int childIndex,
		ChildField<?> childField)
	{
		if(childField == target)
			return new JTreeLabel("Take", false);
		else if(childField == iter)
			return new JTreeLabel("from", false);
		else
			return new JTreeLabel("if", false);
	}
}
